package com.aiyige.page.my.wallet.adapter;

import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.aiyige.R;
import com.aiyige.model.WalletDetailEntity;
import com.aiyige.utils.StringUtils;
import com.aiyige.utils.TimeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.LinkedList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class WalletDetailsListAdapter extends BaseQuickAdapter<WalletDetailEntity, BaseViewHolder> {

    @Override
    protected void convert(BaseViewHolder helper, WalletDetailEntity item) {
        ((MyHolder) helper).bindData(item);
    }

    public WalletDetailsListAdapter() {
        super(new LinkedList<WalletDetailEntity>());
    }

    @Override
    protected BaseViewHolder onCreateDefViewHolder(ViewGroup parent, int viewType) {
        BaseViewHolder baseViewHolder = new MyHolder(getItemView(R.layout.item_wallet_details, parent));
        return baseViewHolder;
    }

    public class MyHolder extends BaseViewHolder {
        @BindView(R.id.tv_price)
        TextView tvPrice;
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.tv_wallet_balance)
        TextView tvWalletBalance;
        @BindView(R.id.tv_time)
        TextView tvTime;

        WalletDetailEntity entity;

        public MyHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }


        public void bindData(final WalletDetailEntity baseEntity) {
            entity = baseEntity;
            if (entity.getType() != null && entity.getType().equals("outlay")) {
                tvPrice.setText("-" + StringUtils.priceFormat(entity.getAmount()));
            } else {
                tvPrice.setText("+" + StringUtils.priceFormat(entity.getAmount()));
            }
            tvTitle.setText(entity.getDescribe());
            tvWalletBalance.setText(mContext.getString(R.string.wallet_balance) + StringUtils.priceFormat(entity.getBalance()));
            tvTime.setText(TimeUtils.dateToYYYYMMDDHHMM(entity.getCreateTime()));
            tvPrice.setTextColor(ContextCompat.getColor(mContext, entity.isIncome() ? R.color.zwcolor_pink_f93684 : R.color.zwcolor_black_111111));
        }
    }

}
